#ifndef __uentry_h__
#define __uentry_h__ 1
#include "sys.h"
#include "log.h"
#include "net.h"
#include "hash_table.h"
typedef struct{
    int fd;
    uint16_t port;
    struct sockaddr_in ctl_addr, peer_addr, local_addr;
    socklen_t peer_addr_len;
    struct hashTable *htable;
    struct hashNode *hnode;
}uentry_t;

typedef struct{
    uint64_t bytes;
    uint64_t packets;
    int duration;//ms
    float rate;
}uentry_trans_info_t;

uentry_t *uentry_new();
int uentry_bind(uentry_t* ue, uint16_t cur_port, uint16_t min_port, uint16_t max_port);
void uentry_free(uentry_t *ue);
void* uentry_run(void* arg);
int ratelimit(uint64_t start_us, uint64_t cur_bytes, uint64_t limit_rate);
int uentry_cmp(uentry_t *a, uentry_t *b);
uint32_t uentry_hash_key(struct sockaddr_in *addr);
#endif